//const pubUrl = 'http://192.168.77.41:8886/index.php' //这是我要请求的数据接口的公共部分
//const pubHost = 'http://192.168.77.41:8886/'
let pubUrl = 'http://192.168.1.218:8886/index.php' //这是我要请求的数据接口的公共部分
let pubHost = 'http://192.168.1.218:8886/'
// const pubUrl = 'http://wms:91/index.php' //这是我要请求的数据接口的公共部分
// const pubUrl = 'http://192.168.1.106:89/index.php' //测试

// 同步请求封装
const request = (options) => {
	let flag = false
	uni.getNetworkType({
		success: function (res) {
			//console.log(res.networkType);//网络类型 wifi、2g、3g、4g、ethernet、unknown、none
			if (res.networkType === "wifi" || res.networkType === '4g' || res.networkType === '5g') {
				flag = true;
			}else{
				uni.showToast({
					title:'网络异常',
					icon:'error'
				})
			}
		},
	})
	
	if(flag){
		return new Promise((resolve, reject) => {
			let myconfig = uni.getStorageSync('myconfig');
			if(myconfig!=''){
				pubHost = myconfig.url+"/"
				pubUrl = myconfig.url+'/index.php'
			}
			//console.log(pubHost)
			//console.log(pubUrl)
			uni.request({
				url: pubUrl + options.url,
				method: options.method || 'get',
				data: options.data || {},
				header: options.header || {
					'content-type': 'application/json'
				},
				success: function(e){
					if(e.statusCode == 200){
						resolve(e)
					}else{
						reject('请求地址、接口不存在、服务器500异常')
					}
				},
				fail: function(e){
					uni.hideLoading()
					uni.showToast({
						title:'网络异常或不通',
						icon:'error'
					})
				}
			})
		})
	}else{
		return new Promise((resolve, reject) => { reject("错误请求：网络异常或不通") });
	}
};

const getPubUrl = () => {
	console.log(123)
};
export {pubUrl,pubHost};
export default request;

